package com.ruoyi.merchant.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.merchant.dto.PositionsDto;
import com.ruoyi.merchant.entity.Positions;
import com.ruoyi.merchant.service.IPositionsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName PositionsController
 * @Description TODO
 * @Author chenxin.ju
 * @Date 2020-07-13 22:24
 * @ProjectName juservicecloud
 * @Version 1.0
 **/
@Slf4j
@RestController
@RequestMapping("/api/postition")
public class PositionsController extends BaseController {



    @Autowired
    private IPositionsService positionsService;

    /**
     *  获取24内的坐标位置
     * @Author chengxin.ju
     **/
    @PostMapping("/getPositions")
    public AjaxResult getPositions(@RequestBody Positions positions) {
        List<Positions>  positionsList = null;
        try{
            if (StringUtils.isBlank(positions.getImei())){
                return error("参数错误，设备识编码imie");
            }
            positionsList = positionsService.getPositions(positions.getImei());
        }catch (Exception e){
            log.error("listByDeviceId",e);
            return error("查询设备绑定电子围栏");
        }
        return success(positionsList);
    }

    /**
     *  获取设备打当前位置坐标
     **/
    @PostMapping("/getNewPosition")
    public AjaxResult getNewPosition(@RequestBody PositionsDto positionsDto) {
        try{
            if (StringUtils.isBlank(positionsDto.getImei())){
                return error("设备识别码不能为空!!");
            }
            positionsDto = positionsService.getNewPosition(positionsDto);
            if (positionsDto == null){
                return error("获取设备打当前位置坐标定位中!!");
            }


        }catch (Exception e){
            log.error("getNewPosition",e);
            return error("获取设备打当前位置坐标是失败");
        }
        return success(positionsDto);
    }

}
